package com.qf.java2201.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.java2201.common.PageVo;
import com.qf.java2201.mapper.UsersMapper;
import com.qf.java2201.pojo.Users;
import com.qf.java2201.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("usersService")
public class UsersServiceImpl implements UsersService {

    @Autowired
    private UsersMapper usersMapper;

    @Override
    public PageVo<Users> getPageDate(Map<String, Object> params) {

        String page = (String) params.get("page");
        String limit = (String) params.get("limit");
        //mybatis
        PageHelper.startPage(Integer.parseInt(page),Integer.parseInt(limit));

        List<Users> users = usersMapper.selectByParams(params);

        PageInfo<Users> pageInfo = new PageInfo<>(users);
        PageVo<Users> usersPageVo = new PageVo<>();
        usersPageVo.setData(pageInfo.getList());
        usersPageVo.setCode(0);
        usersPageVo.setCount(pageInfo.getTotal());
        usersPageVo.setMsg("用户列表");
        return usersPageVo;
    }

    @Override
    public int addUsers(Users users) {
        return usersMapper.addUsers(users);
    }

    @Override
    public int deleteUsersById(Integer user_id) {
        return usersMapper.deleteUsersById(user_id);
    }

    @Override
    public int updateUsersById(Users users) {
        return usersMapper.updateUsersById(users);
    }

    @Override
    public List<Users> selectUsersCond(Users users) {
        return usersMapper.selectUsersCond(users);
    }
}
